package com.networklib.task.service;


import com.networklib.http.impl.ProgressRequestBodyImpl;
import com.networklib.http.impl.ProgressResponseBodyImpl;
import com.networklib.task.base.ATask;
import com.networklib.task.base.TaskService;
import com.networklib.task.impl.DownloadHttpTask;
import com.networklib.task.impl.UploadFileTask;

public class UploadExcute extends ConcurrentExcute implements ProgressRequestBodyImpl.ProgressListener {
    private UploadFileTask uploadFileTask;

    @Override
    public final TaskService addTask(ATask aTask) {
        if (aTask instanceof UploadFileTask) {
            this.uploadFileTask = (UploadFileTask) aTask;
            this.submit(aTask);
            this.uploadFileTask.addUpProgressListener(this);
        }
        return this;
    }

    public ConcurrentExcute addTask(ATask... aTasks) {
        if (aTasks != null) {
            for (ATask aTask : aTasks) {
                if (aTask instanceof UploadFileTask) {
                    this.uploadFileTask = (UploadFileTask) aTask;
                    this.addTask(aTask);
                    this.uploadFileTask.addUpProgressListener(this);
                }
            }
        }
        return this;
    }

    @Override
    public void update(long bytesRead, long contentLength, boolean done) {
//        this.postProgress(this.uploadFileTask, (float)(100L * bytesRead / contentLength), done);
    }
}
